package com.gamejelly.broker.processor.message;

import com.alipay.remoting.BizContext;
import com.alipay.remoting.rpc.protocol.SyncUserProcessor;
import com.gamejelly.broker.message.RegisterMsg;
import com.gamejelly.broker.server.BrokerServer;
import com.gamejelly.broker.server.BrokerServerAware;

public class RegisterHandler extends SyncUserProcessor<RegisterMsg> implements BrokerServerAware {
    BrokerServer server;

    @Override
    public Object handleRequest(BizContext bizContext, RegisterMsg registerMsg) throws Exception {
        String id = server.register(bizContext.getRemoteAddress(), registerMsg);
        if (id != null)
            bizContext.getConnection().setAttribute("id", id);
        return id;
    }

    @Override
    public String interest() {
        return RegisterMsg.class.getName();
    }

    @Override
    public void setServer(BrokerServer server) {
        this.server = server;
    }
}
